<?php
if (!defined('FosfoaSystem')) {
    exit(1);
}
import($GLOBALS['spConfig']['controller_path'] . '/general.php');
class system extends general
{
    public function __construct()
    {
        parent::__construct();

        $this->tpl_title = T("Dashboard");
    }
    function index()
    {
        $this->tt = "系统首页";
        $this->display("admin/system_index.html");
    }
    function rates()
    {
        $this->tt = "银行利率";
        $this->rates = spClass('currenciesModel')->findAll(null, 'currencies_id asc');
        $this->display("admin/system_rates.html");
    }
    function addrates()
    {
        $this->addtitle = "添加新利率";
        $this->ajaxwait = $this->ajaxwait();
        $this->display("admin/system_addrates.html");
    }
    function editrates()
    {
        $currencies_id = $this->spArgs("currencies_id", 0);
        $Obj = spClass('currenciesModel');
        $conditions = array("currencies_id" => $currencies_id);
        $rates = $Obj->find($conditions);
        $this->rates = $rates;
        $this->addtitle = "修改分类";
        $this->display("admin/system_addrates.html");
    }
    function saverates()
    {
        $currencies_id = $this->spArgs("currencies_id", 0);
        $title = urldecode($this->spArgs("title"));
        $code = $this->spArgs("code");
        $symbol_left = urldecode($this->spArgs("symbol_left"));
        $value = $this->spArgs("value");
        $dataform = array(
            'title' => $title,
            'code' => $code,
            'symbol_left' => $symbol_left,
            'value' => $value,
            'last_updated' => date('Y-m-d H:i:s', time()));
        $Obj = spClass('currenciesModel');

        if ($currencies_id == 0) {
            $Obj->create($dataform);
            $msg = "添加" . $dataform[title] . "成功";
        } else {
            $condition = array('currencies_id' => $currencies_id);
            $Obj->update($condition, $dataform);
            $msg = "修改" . $dataform[title] . "成功";

        }

        Savelog($msg);
        $result = array(
            'status' => 1,
            'info' => $msg,
            );
        echo json_encode($result);
    }
    function delrates()
    {
        $Obj = spClass("currenciesModel");
        $id2 = $this->spArgs("currencies_id", 0);
        if ($id2 == 0) {
            $ids = $this->spArgs("selids");
            $idsarray = explode(',', $ids);

            foreach ($idsarray as $id) {
                $conditions = array('currencies_id' => $id);
                $Obj->delete($conditions); // 删除记录
            }
        } else {

            $conditions = array('currencies_id' => $id2);
            $Obj->delete($conditions); // 删除记录
        }
        $msg = "删除利率" . $id2;
        $this->log($msg);
        $this->success(T('Successfully  deleted!'), spUrl("system", "rates"));

    }
    function editratesvalue()
    {
        $selids = $this->spArgs("selids");
        $orderid = $this->spArgs("orderid");
        $Obj = spClass('currenciesModel');
        $selarray = explode(',', $selids);

        foreach ($selarray as $currencies_id) {
            $condition = array('currencies_id' => $currencies_id);
            $dataform = array('value' => $orderid[$currencies_id]);
            $Obj->update($condition, $dataform);
        }
        $this->success(T('Successfully Order!'), spUrl("system", "rates"));
    }
    //远程抓取利率
    function update()
    {
        //ini_set('max_execution_time', '0');
        $Obj = spClass('currenciesModel');
        $rates = $Obj->findAll(null, 'currencies_id asc');
        //dump($rates);
        //exit;
        foreach ($rates as $currency) {

            $code = $currency['code'];
            if ($currency['code'] != DEFAULT_CURRENCY) {

                //echo $yahoo = "http://download.finance.yahoo.com/d/quotes.html?s=".DEFAULT_CURRENCY.$code."=X&f=l1";
                $rate = $this->quote_yahoo_currency($code);
                if ($rate) {


                    $condition = array('currencies_id' => $currency['currencies_id']);
                    $dataform = array('value' => $rate, 'last_updated' => date('Y-m-d H:i:s', time()));
                    $Obj->update($condition, $dataform);
                    $msg = $code . ":" . $rate . "更新成功..\r\n";
                }
            }
        }
        echo $msg;
        Savelog($msg);
        $this->success("指量更新成功", spUrl("system", "rates")); // 返回利率页！
    }

    //
    // Function for currency lookup
    //
    function quote_yahoo_currency($code, $base = DEFAULT_CURRENCY)
    {

        $yahoo = "http://download.finance.yahoo.com/d/quotes.html?s=" . $base . $code .
            "=X&f=l1";
        $yahoocontent = @file_get_contents($yahoo);
        $currency = number_format($yahoocontent, 2, '.', '');
        return $currency;
    }
    //Automatic Currency Update
    function update22()
    {
        $Obj = spClass('currenciesModel');

        $xml = @new SimpleXMLElement(file_get_contents("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"));

        //extract your preferred currency's exchange rate.
        $nzd = $xml->xpath("//*[@currency='" . DEFAULT_CURRENCY . "']");
        $base = (float)$nzd[0]['rate'];
        //
        if (DEFAULT_CURRENCY == 'EUR')
            $base = (float)1;

        $currencies = $xml->xpath("//*[@currency]");

        foreach ($currencies as $curr) {
            $cc = $curr[0]['currency'];
            $rr = (float)$curr[0]['rate'] * CURRENCY_UPLIFT_RATIO;
            $new = $rr / $base;
            //echo $cc."<br/>".$rr."<br/>".$new;
            # But don't uplift your default currency!
            if ($cc != DEFAULT_CURRENCY) {

                echo $cc . "<br/>" . $rr . "<br/>" . $new . "<br/>";
            }
        }

        //dump($currencies);
    }
    function set()
    {
        $this->tt = "网站配置";
        $this->sitename = SITENAME;
        $this->storename = STORENAME;
        $this->keywords = KEYWORDS;
        $this->description = DESCRIPTION;
        $this->Flogin = FLOGIN;
        $this->paypalother = PAYPALOTHER;
        $this->freight = FREIGHT;
        $this->KD = KD;
        //dump(KD);
        $KD = trim(KD);
        $arr = explode(chr(13), $KD);
        foreach ($arr as $k => $v) {
            $shippingarr[$k] = explode('/', trim($v));
        }
        $this->shippingarr = $shippingarr;
        $this->westernunion_code = WESTERNUNION_CODE;
        $this->westernunion_order_status_id = WESTERNUNION_ORDER_STATUS_ID;
        $this->westernunion_money = WESTERNUNION_MONEY;
        $this->westernunion_type = WESTERNUNION_TYPE;
        $this->westernunion_Country = WESTERNUNION_COUNTRY;
        $this->westernunion_City = WESTERNUNION_CITY;
        $this->westernunion_LastName = WESTERNUNION_LASTNAME;
        $this->westernunion_FirstName = WESTERNUNION_FIRSTNAME;

        $this->alipay_code = ALIPAY_CODE;
        $this->alipay_partner = ALIPAY_PARTNER;
        $this->alipay_key = ALIPAY_KEY;
        $this->alipay_email = ALIPAY_EMAIL;
        $this->alipay_order_status_id = ALIPAY_ORDER_STATUS_ID;
        $this->alipay_type = ALIPAY_TYPE;

        $this->rppay_code = RPPAY_CODE;
        $this->rppay_siteid = RPPAY_SITEID;
        $this->rppay_miyao = RPPAY_MIYAO;
        $this->rppay_http = RPPAY_HTTP;
        $this->rppay_order_status_id = RPPAY_ORDER_STATUS_ID;
        $this->rppay_type = RPPAY_TYPE;

        $this->rppay_M_code = RPPAY_M_CODE;
        $this->rppay_M_siteid = RPPAY_M_SITEID;
        $this->rppay_M_miyao = RPPAY_M_MIYAO;
        $this->rppay_M_http = RPPAY_M_HTTP;
        $this->rppay_M_order_status_id = RPPAY_M_ORDER_STATUS_ID;
        $this->rppay_M_type = RPPAY_M_TYPE;

        $this->weburl = WEBURL;
        $this->webdir = WEBDIR;
        $this->allcp = ALLCP;
        $this->flcp = FLCP;
        $this->sjcp = SJCP;
        $this->socp = SOCP;
        $this->ximgw = XIMGW;
        $this->ximgh = XIMGH;
        $this->newsimgw = NEWSIMGW;
        $this->newsimgh = NEWSIMGH;
        $this->imgw = IMGW;
        $this->imgh = IMGH;
        $this->fimgh = FIMGH;
        $this->fimgw = FIMGW;
        $this->Attribs = ATTRIBS;
        $this->pl = PL;
        $this->ykpl = YKPL;
        $this->plsh = PLSH;
        $this->plstr = PLSTR;
        $this->skin_name = __SKIN_NAME;
        $this->skin_name_ht = __SKIN_NAME_HT;
        $this->replyemail = REPLYEMAIL;
        $this->smtpsecure = SMTPSECURE;
        $this->send_type = SEND_TYPE;
        $this->smtp_debug = SMTP_DEBUG;
        $this->smtp_authenticate = SMTP_AUTHENTICATE;
        $this->smtp = SMTP;
        $this->mailuser = MAILUSER;
        $this->mailpass = MAILPASS;
        $this->mailport = MAILPORT;
        $this->default_currency = DEFAULT_CURRENCY;
        $this->rssnews = RSSNEWS;
        $this->foototherok = FOOTOTHEROK;
        $this->footother = stripslashes(FOOTOTHER);
        $this->footother2 = stripslashes(FOOTOTHER2);
        $this->default_payment = DEFAULT_PAYMENT;
        $this->ips_code = IPS_CODE;
        $this->ips_siteid = IPS_SITEID;
        $this->ips_miyao = IPS_MIYAO;
        $this->ips_http = IPS_HTTP;
        $this->ips_order_status_id = IPS_ORDER_STATUS_ID;
        $this->ips_type = IPS_TYPE;
        $this->paypal_EC_code = PAYPAL_EC_CODE;
        $this->paypal_EC_Account = PAYPAL_EC_ACCOUNT;
        $this->paypal_EC_ADDRESS = PAYPAL_EC_ADDRESS;
        $this->paypal_EC_Signature = PAYPAL_EC_SIGNATURE;
        $this->paypal_EC_SignaturePassword = PAYPAL_EC_SIGNATUREPASSWORD;
        $this->paypal_EC_http = PAYPAL_EC_HTTP;
        $this->paypal_EC_API_http = PAYPAL_EC_API_HTTP;
        $this->paypal_EC_paymentType = PAYPAL_EC_PAYMENTTYPE;
        $this->paypal_EC_order_status_id = PAYPAL_EC_ORDER_STATUS_ID;
        $this->paypal_EC_type = PAYPAL_EC_TYPE;
        $this->home_lht_num = HOME_LHT_NUM;
        $this->home_lht_num_type = HOME_LHT_NUM_TYPE;
        $this->home_products = HOME_PRODUCTS;
        $this->home_products_order = HOME_PRODUCTS_ORDER;
        $this->home_products_type = HOME_PRODUCTS_TYPE;
        $this->home_news = HOME_NEWS;
        $this->home_news_type = HOME_NEWS_TYPE;
        $this->home_news_img_type = HOME_NEWS_IMG_TYPE;
        $this->home_news_product = HOME_NEWS_PRODUCT;
        $this->home_news_product_type = HOME_NEWS_PRODUCT_TYPE;
        $this->home_news_product_xz = HOME_NEWS_PRODUCT_XZ;
        $this->home_news_product_xz_type = HOME_NEWS_PRODUCT_XZ_TYPE;
        $this->allnews = ALLNEWS;
        $this->rightnews = RIGHTNEWS;

        $this->qq_appid = QQ_APPID;
        $this->qq_appkey = QQ_APPKEY;
        $this->qq_type = QQ_TYPE;

        $this->facebook_appId = FACEBOOK_APPID;
        $this->facebook_secret = FACEBOOK_SECRET;
        $this->facebook_type = FACEBOOK_TYPE;

        $this->price_type = PRICE_TYPE;
        $this->price_gd = PRICE_GD;

        $this->price_type_arr = array(
            '1' => '不限显示优惠价',
            '2' => '只有会员显示优惠价',
            '3' => '只有会员显示固定价',
            '4' => '不限显示固定价',
            '5' => '只在购物车中显示固定价');
        $this->paytype = array('False' => '关', 'True' => '开');
        $this->type_1 = array('False' => '关', 'True' => '开');
        $this->type_2 = array('False' => '不过滤', 'True' => '过滤');
        $this->type_3 = array('False' => '不限', 'True' => '限制');
        $this->type_order = array(
            1 => '随机',
            2 => '最新',
            3 => '最旧',
            4 => '价格低到高',
            5 => '价格高到低',
            6 => '销售排行',
            6 => '人气');
        $this->payment = array(
            'IPS' => 'IPS环迅支付',
            'rppay' => 'RPPAY日付',
            'rppay_m' => 'RPPAY master卡',
            'paypal_ec' => 'PAYPAL',
            'WesternUnion' => '西联电汇',
            'Alipay' => '支付宝即时到帐');
        $this->paypal_httparr = array('https://api-3t.sandbox.paypal.com/nvp' => '测试地址',
                'https://api-3t.paypal.com/nvp' => '正式地址');
        $this->paypal_paymentType = array(
            'Sale' => 'Sale',
            'Authorization' => 'Authorization',
            'Order' => 'Order');
        $this->footothertype = array(
            1 => '首页显示',
            2 => '全站显示',
            3 => '不显示');
        $this->setnum = array(
            1 => '1条',
            2 => '2条',
            3 => '3条',
            4 => '4条',
            5 => '5条',
            6 => '6条',
            7 => '7条',
            8 => '8条',
            9 => '9条',
            10 => '10条',
            12 => '12条',
            15 => '15条',
            18 => '18条',
            20 => '20条',
            30 => '30条');
        $this->send_typearr = array(
            'mail' => 'Mail()',
            'sendmail' => 'Sendmail',
            'qmail' => 'Qmail',
            'smtp' => 'SMTP');
        $this->smtp_authenticatearr = array(false => '不验证', true => '验证');
        $this->smtp_debugarr = array(
            0 => '0 - Disabled',
            1 => '1 - Errors and Messages',
            2 => '2 - Messages only');
        $this->rates = $rates = spClass('currenciesModel')->findAll(null,
            'currencies_id asc');
        $template_arr = $this->template();
        //dump($template_arr);
        $this->template = $template_arr;
        $orders_status = spClass('orders_statusModel')->findAll();
        $this->orders_status = $orders_status;
        $this->display("admin/system_set.html");
    }

    function saveset()
    {

        $sitename = $this->spArgs("sitename");
        $storename = $this->spArgs("storename");
        $keywords = $this->spArgs("keywords");
        $description = $this->spArgs("description");
        $weburl = $this->spArgs("weburl");
        $webdir = $this->spArgs("webdir");
        $paypalother = $this->spArgs("paypalother");
        $Flogin = $this->spArgs("Flogin");
        $default_currency = $this->spArgs("default_currency");
        $rssnews = $this->spArgs("rssnews");
        $freight = $this->spArgs("freight");

        $westernunion_code = $this->spArgs("westernunion_code");
        $westernunion_type = $this->spArgs("westernunion_type");
        $westernunion_money = $this->spArgs("westernunion_money");
        $westernunion_order_status_id = $this->spArgs("westernunion_order_status_id");
        $westernunion_Country = $this->spArgs("westernunion_Country");
        $westernunion_City = $this->spArgs("westernunion_City");
        $westernunion_LastName = $this->spArgs("westernunion_LastName");
        $westernunion_FirstName = $this->spArgs("westernunion_FirstName");

        $alipay_code = $this->spArgs("alipay_code");
        $alipay_partner = $this->spArgs("alipay_partner");
        $alipay_key = $this->spArgs('alipay_key');
        $alipay_email = $this->spArgs('alipay_email');
        $alipay_order_status_id = $this->spArgs('alipay_order_status_id');
        $alipay_type = $this->spArgs('alipay_type');

        $rppay_code = $this->spArgs("rppay_code");
        $rppay_siteid = $this->spArgs("rppay_siteid");
        $rppay_miyao = $this->spArgs("rppay_miyao");
        $rppay_http = $this->spArgs("rppay_http");
        $rppay_order_status_id = $this->spArgs("rppay_order_status_id");
        $rppay_type = $this->spArgs("rppay_type");

        $rppay_M_code = $this->spArgs("rppay_M_code");
        $rppay_M_siteid = $this->spArgs("rppay_M_siteid");
        $rppay_M_miyao = $this->spArgs("rppay_M_miyao");
        $rppay_M_http = $this->spArgs("rppay_M_http");
        $rppay_M_order_status_id = $this->spArgs("rppay_M_order_status_id");
        $rppay_M_type = $this->spArgs("rppay_M_type");

        $allcp = $this->spArgs("allcp");
        $flcp = $this->spArgs("flcp");
        $sjcp = $this->spArgs("sjcp");
        $socp = $this->spArgs("socp");
        $newsimgw = $this->spArgs("newsimgw");
        $newsimgh = $this->spArgs("newsimgh");
        $ximgw = $this->spArgs("ximgw");
        $ximgh = $this->spArgs("ximgh");
        $imgh = $this->spArgs("imgh");
        $imgw = $this->spArgs("imgw");
        $fimgw = $this->spArgs("fimgw");
        $fimgh = $this->spArgs("fimgh");
        $Attribs = $this->spArgs("Attribs");

        $pl = $this->spArgs("pl");
        $ykpl = $this->spArgs("ykpl");
        $plsh = $this->spArgs("plsh");
        $plstr = $this->spArgs("plstr");
        $skin_name = $this->spArgs("skin_name");
        $skin_name_ht = $this->spArgs("skin_name_ht");
        $replyemail = $this->spArgs("replyemail");
        $smtpsecure = $this->spArgs("smtpsecure");
        $send_type = $this->spArgs('send_type');
        $smtp_debug = $this->spArgs('smtp_debug');
        $smtp_authenticate = $this->spArgs('smtp_authenticate');

        $smtp = $this->spArgs("smtp");
        $mailuser = $this->spArgs("mailuser");
        $mailpass = $this->spArgs("mailpass");
        $mailport = $this->spArgs("mailport");
        $foototherok = $this->spArgs('foototherok', 1);
        $footother = $this->spArgs('footother');
        $footother2 = $this->spArgs('footother2');
        $default_payment = $this->spArgs('default_payment');

        $ips_code = $this->spArgs("ips_code");
        $ips_siteid = $this->spArgs("ips_siteid");
        $ips_miyao = $this->spArgs("ips_miyao");
        $ips_http = $this->spArgs("ips_http");
        $ips_order_status_id = $this->spArgs("ips_order_status_id");
        $ips_type = $this->spArgs("ips_type");

        $paypal_EC_code = $this->spArgs("paypal_EC_code");
        $paypal_EC_Account = $this->spArgs("paypal_EC_Account");
        $paypal_EC_ADDRESS = $this->spArgs("paypal_EC_ADDRESS");
        $paypal_EC_Signature = $this->spArgs("paypal_EC_Signature");
        $paypal_EC_SignaturePassword = $this->spArgs("paypal_EC_SignaturePassword");
        $paypal_EC_http = $this->spArgs("paypal_EC_http");
        $paypal_EC_API_http = $this->spArgs("paypal_EC_API_http");
        $paypal_EC_paymentType = $this->spArgs('paypal_EC_paymentType');
        $paypal_EC_order_status_id = $this->spArgs("paypal_EC_order_status_id");

        $paypal_EC_type = $this->spArgs("paypal_EC_type");

        $home_lht_num = $this->spArgs('home_lht_num');
        $home_lht_num_type = $this->spArgs('home_lht_num_type');

        $home_products = $this->spArgs('home_products');
        $home_products_order = $this->spArgs('home_products_order');
        $home_products_type = $this->spArgs('home_products_type');

        $home_news = $this->spArgs('home_news');
        $home_news_img_type = $this->spArgs('home_news_img_type');
        $home_news_type = $this->spArgs('home_news_type');

        $home_news_product = $this->spArgs('home_news_product');
        $home_news_product_type = $this->spArgs('home_news_product_type');
        $home_news_product_xz = $this->spArgs('home_news_product_xz');
        $home_news_product_xz_type = $this->spArgs('home_news_product_xz_type');
        $allnews = $this->spArgs('allnews');
        $rightnews = $this->spArgs('rightnews');

        $qq_appid = $this->spArgs('qq_appid');
        $qq_appkey = $this->spArgs('qq_appkey');
        $qq_type = $this->spArgs("qq_type");

        $facebook_appId = $this->spArgs('facebook_appId');
        $facebook_secret = $this->spArgs('facebook_secret');
        $facebook_type = $this->spArgs("facebook_type");

        $KD = $this->spArgs('KD');
        $price_type = $this->spArgs('price_type');
        $price_gd = $this->spArgs('price_gd');

        $config_str = "<?php";
        $config_str .= "\n";
        $config_str .= "define(\"SITENAME\", \"" . $sitename . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"STORENAME\", \"" . $storename . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"KEYWORDS\", \"" . $keywords . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"DESCRIPTION\", \"" . $description . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"FLOGIN\", \"" . $Flogin . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"PAYPALOTHER\", \"" . $paypalother . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"DEFAULT_CURRENCY\", " . $default_currency . ");";
        $config_str .= "\n";
        $config_str .= "define(\"RSSNEWS\", " . $rssnews . ");";
        $config_str .= "\n";
        $config_str .= "define(\"FREIGHT\", \"" . $freight . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"KD\", \"" . $KD . "\");";
        $config_str .= "\n";

        $config_str .= "define(\"WESTERNUNION_CODE\", \"" . $westernunion_code . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"WESTERNUNION_TYPE\", \"" . $westernunion_type . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"WESTERNUNION_MONEY\", " . $westernunion_money . ");";
        $config_str .= "\n";
        $config_str .= "define(\"WESTERNUNION_ORDER_STATUS_ID\", \"" . $westernunion_order_status_id .
            "\");";
        $config_str .= "\n";

        $config_str .= "define(\"WESTERNUNION_COUNTRY\", \"" . $westernunion_Country . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"WESTERNUNION_CITY\", \"" . $westernunion_City . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"WESTERNUNION_LASTNAME\", \"" . $westernunion_LastName .
            "\");";
        $config_str .= "\n";
        $config_str .= "define(\"WESTERNUNION_FIRSTNAME\", \"" . $westernunion_FirstName .
            "\");";
        $config_str .= "\n";

        $config_str .= "define(\"ALIPAY_CODE\", \"" . $alipay_code . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"ALIPAY_PARTNER\", \"" . $alipay_partner . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"ALIPAY_KEY\", \"" . $alipay_key . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"ALIPAY_EMAIL\", \"" . $alipay_email . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"ALIPAY_ORDER_STATUS_ID\", \"" . $alipay_order_status_id .
            "\");";
        $config_str .= "\n";
        $config_str .= "define(\"ALIPAY_TYPE\", \"" . $alipay_type . "\");";
        $config_str .= "\n";

        $config_str .= "define(\"RPPAY_CODE\", \"" . $rppay_code . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"RPPAY_SITEID\", \"" . $rppay_siteid . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"RPPAY_MIYAO\", \"" . $rppay_miyao . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"RPPAY_HTTP\", \"" . $rppay_http . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"RPPAY_ORDER_STATUS_ID\", \"" . $rppay_order_status_id .
            "\");";
        $config_str .= "\n";
        $config_str .= "define(\"RPPAY_TYPE\", \"" . $rppay_type . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"RPPAY_M_CODE\", \"" . $rppay_M_code . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"RPPAY_M_SITEID\", \"" . $rppay_M_siteid . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"RPPAY_M_MIYAO\", \"" . $rppay_M_miyao . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"RPPAY_M_HTTP\", \"" . $rppay_M_http . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"RPPAY_M_ORDER_STATUS_ID\", \"" . $rppay_M_order_status_id .
            "\");";
        $config_str .= "\n";
        $config_str .= "define(\"RPPAY_M_TYPE\", \"" . $rppay_M_type . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"HOME_LHT_NUM\", " . $home_lht_num . ");";
        $config_str .= "\n";
        $config_str .= "define(\"HOME_LHT_NUM_TYPE\", \"" . $home_lht_num_type . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"HOME_PRODUCTS\", " . $home_products . ");";
        $config_str .= "\n";
        $config_str .= "define(\"HOME_PRODUCTS_ORDER\", " . $home_products_order . ");";
        $config_str .= "\n";
        $config_str .= "define(\"HOME_PRODUCTS_TYPE\", \"" . $home_products_type . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"HOME_NEWS\", " . $home_news . ");";
        $config_str .= "\n";
        $config_str .= "define(\"HOME_NEWS_IMG_TYPE\", \"" . $home_news_img_type . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"HOME_NEWS_TYPE\", \"" . $home_news_type . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"HOME_NEWS_PRODUCT\", " . $home_news_product . ");";
        $config_str .= "\n";
        $config_str .= "define(\"HOME_NEWS_PRODUCT_TYPE\", \"" . $home_news_product_type .
            "\");";
        $config_str .= "\n";
        $config_str .= "define(\"HOME_NEWS_PRODUCT_XZ\", " . $home_news_product_xz .
            ");";
        $config_str .= "\n";
        $config_str .= "define(\"HOME_NEWS_PRODUCT_XZ_TYPE\", \"" . $home_news_product_xz_type .
            "\");";
        $config_str .= "\n";
        $config_str .= "define(\"ALLNEWS\", " . $allnews . ");";
        $config_str .= "\n";
        $config_str .= "define(\"RIGHTNEWS\", " . $rightnews . ");";
        $config_str .= "\n";
        $config_str .= "define(\"PRICE_TYPE\", " . $price_type . ");";
        $config_str .= "\n";
        $config_str .= "define(\"PRICE_GD\", " . $price_gd . ");";
        $config_str .= "\n";
        $config_str .= "define(\"ALLCP\", \"" . $allcp . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"FLCP\", \"" . $flcp . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"SJCP\", \"" . $sjcp . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"SOCP\", \"" . $socp . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"NEWSIMGW\", \"" . $newsimgw . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"NEWSIMGH\", \"" . $newsimgh . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"XIMGW\", \"" . $ximgw . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"XIMGH\", \"" . $ximgh . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"IMGW\", \"" . $imgw . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"IMGH\", \"" . $imgh . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"FIMGW\", \"" . $fimgw . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"FIMGH\", \"" . $fimgh . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"ATTRIBS\", \"" . $Attribs . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"PL\", \"" . $pl . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"YKPL\", \"" . $ykpl . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"PLSH\", \"" . $plsh . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"PLSTR\", \"" . $plstr . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"WEBURL\", \"" . $weburl . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"__SKIN_NAME\", \"" . $skin_name . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"__SKIN_NAME_HT\", \"" . $skin_name_ht . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"REPLYEMAIL\", \"" . $replyemail . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"SMTPSECURE\", \"" . $smtpsecure . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"SEND_TYPE\", \"" . $send_type . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"SMTP_DEBUG\", \"" . $smtp_debug . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"SMTP_AUTHENTICATE\", " . $smtp_authenticate . ");";
        $config_str .= "\n";
        $config_str .= "define(\"SMTP\", \"" . $smtp . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"MAILUSER\", \"" . $mailuser . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"MAILPASS\", \"" . $mailpass . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"MAILPORT\", \"" . $mailport . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"WEBDIR\", \"" . $webdir . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"DEFAULT_PAYMENT\", \"" . $default_payment . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"IPS_CODE\", \"" . $ips_code . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"IPS_SITEID\", \"" . $ips_siteid . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"IPS_MIYAO\", \"" . $ips_miyao . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"IPS_HTTP\", \"" . $ips_http . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"IPS_ORDER_STATUS_ID\", \"" . $ips_order_status_id . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"IPS_TYPE\", \"" . $ips_type . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"PAYPAL_EC_CODE\", \"" . $paypal_EC_code . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"PAYPAL_EC_ACCOUNT\", \"" . $paypal_EC_Account . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"PAYPAL_EC_ADDRESS\", \"" . $paypal_EC_ADDRESS . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"PAYPAL_EC_SIGNATUREPASSWORD\", \"" . $paypal_EC_SignaturePassword .
            "\");";
        $config_str .= "\n";
        $config_str .= "define(\"PAYPAL_EC_SIGNATURE\", \"" . $paypal_EC_Signature . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"PAYPAL_EC_HTTP\", \"" . $paypal_EC_http . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"PAYPAL_EC_API_HTTP\", \"" . $paypal_EC_API_http . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"PAYPAL_EC_PAYMENTTYPE\", \"" . $paypal_EC_paymentType .
            "\");";
        $config_str .= "\n";
        $config_str .= "define(\"PAYPAL_EC_ORDER_STATUS_ID\", \"" . $paypal_EC_order_status_id .
            "\");";
        $config_str .= "\n";
        $config_str .= "define(\"PAYPAL_EC_TYPE\", \"" . $paypal_EC_type . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"QQ_APPID\", \"" . $qq_appid . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"QQ_APPKEY\", \"" . $qq_appkey . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"QQ_TYPE\", \"" . $qq_type . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"FACEBOOK_APPID\", \"" . $facebook_appId . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"FACEBOOK_SECRET\", \"" . $facebook_secret . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"FACEBOOK_TYPE\", \"" . $facebook_type . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"FOOTOTHEROK\", " . $foototherok . ");";
        $config_str .= "\n";
        $config_str .= "define(\"FOOTOTHER\", \"" . $footother . "\");";
        $config_str .= "\n";
        $config_str .= "define(\"FOOTOTHER2\", \"" . $footother2 . "\");";
        $config_str .= "\n";
        $config_str .= "?>";

        $msg = "配置修改成功！！！";
        @file_put_contents("SystemConfig.php", $config_str) or die($msg = "修改失败！！！");
        Savelog($msg);
        $result = array(
            'status' => 'y',
            'info' => $msg,
            );
        echo json_encode($result); // 返回（显示）JSON结果

    }
    function clearCache()
    {

        //        spClass('currenciesModel')->spCache(-1)->findAll();
        //        spClass('countriesModel')->spCache(-1)->findAll();
        //        spClass('orders_statusModel')->spCache(-1)->findAll();
        //        spClass('categoriesModel')->spLinker()->spCache(-1)->findAll();
        //        spClass("newsModel")->spLinker()->spCache(-1)->findAll();
        //        spClass("newsModel")->spLinker()->spCache(-1)->find();
        //        spClass("productsModel")->spCache(-1)->findSql();
        //        spClass("productsModel")->spCache(-1)->findAll();
        //        spClass("productsModel")->spCache(-1)->find();
        //        spClass("newsModel")->spCache(-1)->findSql();
        //        spClass("newsModel")->spCache(-1)->findAll();
        //        spClass("newsModel")->spLinker()->spCache(-1)->find();
        //
        //        spClass("newscategoriesModel")->spLinker()->spCache(-1)->findAll();
        //        spClass("newscategoriesModel")->spLinker()->spCache(-1)->find();
        //
        //        spClass("tagModel")->spCache(-1)->find();
        //        spClass("adModel")->spCache(-1)->findAll();
        //        spClass("spAclModel")->spCache(-1)->findAll();


        spClass("sqlModel")->spCache()->clear_all();
        $msg = "清除缓存成功！谢谢配合";
        Savelog($msg);
        $this->success($msg);
    }
    function sql()
    {
        $sqlstr = $this->spArgs('sqlstr');
        $sqltype = $this->spArgs('sqltype');
        if (get_magic_quotes_gpc()) {
            $sqlstr = stripslashes($sqlstr);
        }
        if ($sqlstr <> '') {
            if ($sqltype == '1') {
                $request = spClass('sqlModel')->returnfindSql($sqlstr);
            }
            if ($sqltype == '2') {
                $request = spClass('sqlModel')->returnsql($sqlstr);
            }
            dump($request);
            $this->sqltype = $sqltype;
            $this->sqlstr = $sqlstr;
            $msg = "方式:" . $sqltype . " SQL:" . $sqlstr;
            $this->log($msg);
        }
        $this->type = array('1' => 'SELECT', '2' => 'UPDATE/DELETE/CREATE');
        $this->tt = '执行SQL';
        $this->display("admin/system_sql.html");
    }

}

class sqlModel extends spModel
{

    public function returnsql($str)
    {
        return $this->runSql($str);
    }

    public function returnfindSql($str)
    {
        return $this->findSql($str);
    }
}